<template>
	<el-dialog title="物资审批对话框" v-model="visible" :width="500" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" ref="dialogForm" label-width="80px" label-position="left">
			<el-form-item label="申请标题">{{title}}</el-form-item>
			<el-form-item label="物资名称">{{suppliesName}}/{{brand}}/{{model}}</el-form-item>
			<el-form-item label="申请数量">{{quantity}}/{{unitName}}</el-form-item>
			<el-form-item label="使用人">{{usedUserName}}</el-form-item>
			<el-form-item label="申请说明">{{remark}}</el-form-item>
			<el-form-item label="审批数量">
				<el-input-number v-model="form.approvalQuantity" placeholder="审批数量" clearable></el-input-number>
			</el-form-item>
			<el-form-item label="审批意见">
				<el-radio-group v-model="form.status">
					<el-radio-button label="1">同意</el-radio-button>
					<el-radio-button label="2">不同意</el-radio-button>
				</el-radio-group>
			</el-form-item>
			<el-form-item label="审批备注">
				<el-input v-model="form.approvalIdea" type="textarea" placeholder="备注说明" maxlength="180" clearable></el-input>
			</el-form-item>
		</el-form>
		<template #footer>
			<el-button @click="visible=false" >取 消</el-button>
			<el-button type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
		</template>
	</el-dialog>
</template>

<script>
export default {
	components: {
	},
	emits: ['success', 'closed'],
	data() {
		return {
			visible: false,
			isSaveing: false,
			title:'',
			quantity:0,
			suppliesName:"",
			brand:"",
			unitName:"",
			model:"",
			usedUserName:"",
			remark:"",
			form: {
				applyId:'',
				approvalQuantity: 0,
				status:'1',
				approvalIdea:""
			},
			rules: {
				approvalQuantity: [
					{required: true, message: '审批数量不能为空！'}
				]
			},
		}
	},
	mounted() {
	},
	methods: {
		//显示
		open(){
			this.visible = true;
			return this;
		},
		//表单提交方法
		submit(){
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					if (this.form.quantity > this.quantity) {
						this.$alert("申请数量不能超过库存数量", "提示", {type: 'error'})
					}else
					{
						this.isSaveing = true;
						var res = await this.$API.office.officeSupplies.approvalOfficeSuppliesApply.post(this.form);
						this.isSaveing = false;
						if(res.code == 200){
							this.$emit('success')
							this.visible = false;
							this.$message.success("操作成功")
						}else{
							this.$alert(res.message, "提示", {type: 'error'})
						}
					}
				}
			})
		},
		//表单注入数据
		setData(data){
			this.title = data.title
			this.brand = data.brand
			this.unitName = data.unitName
			this.quantity = data.quantity
			this.remark = data.remark
			this.model = data.model
			this.usedUserName = data.usedUserName
			this.suppliesName = data.suppliesName
			this.form.applyId = data.applyId
			this.form.approvalQuantity = data.quantity
		}
	}
}
</script>

<style>
</style>
